{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# Fast Fourier Transformations (FFT)"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import pandas as pd\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "import math\n",
        "\n",
        "import warnings\n",
        "warnings.filterwarnings(\"ignore\")\n",
        "\n",
        "# fix_yahoo_finance is used to fetch data \n",
        "import fix_yahoo_finance as yf\n",
        "yf.pdr_override()"
      ],
      "outputs": [],
      "execution_count": 1,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# input\n",
        "symbol = 'AAPL'\n",
        "start = '2012-01-01'\n",
        "end = '2019-09-11'"
      ],
      "outputs": [],
      "execution_count": 2,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset = yf.download(symbol,start,end)"
      ],
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "[*********************100%***********************]  1 of 1 downloaded\n"
          ]
        }
      ],
      "execution_count": 3,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.head()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 4,
          "data": {
            "text/plain": [
              "                 Open       High        Low      Close  Adj Close    Volume\n",
              "Date                                                                       \n",
              "2012-01-03  58.485714  58.928570  58.428570  58.747143  51.269413  75555200\n",
              "2012-01-04  58.571430  59.240002  58.468571  59.062859  51.544937  65005500\n",
              "2012-01-05  59.278572  59.792858  58.952858  59.718571  52.117188  67817400\n",
              "2012-01-06  59.967144  60.392857  59.888573  60.342857  52.662014  79573200\n",
              "2012-01-09  60.785713  61.107143  60.192856  60.247143  52.578468  98506100"
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2012-01-03</th>\n",
              "      <td>58.485714</td>\n",
              "      <td>58.928570</td>\n",
              "      <td>58.428570</td>\n",
              "      <td>58.747143</td>\n",
              "      <td>51.269413</td>\n",
              "      <td>75555200</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2012-01-04</th>\n",
              "      <td>58.571430</td>\n",
              "      <td>59.240002</td>\n",
              "      <td>58.468571</td>\n",
              "      <td>59.062859</td>\n",
              "      <td>51.544937</td>\n",
              "      <td>65005500</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2012-01-05</th>\n",
              "      <td>59.278572</td>\n",
              "      <td>59.792858</td>\n",
              "      <td>58.952858</td>\n",
              "      <td>59.718571</td>\n",
              "      <td>52.117188</td>\n",
              "      <td>67817400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2012-01-06</th>\n",
              "      <td>59.967144</td>\n",
              "      <td>60.392857</td>\n",
              "      <td>59.888573</td>\n",
              "      <td>60.342857</td>\n",
              "      <td>52.662014</td>\n",
              "      <td>79573200</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2012-01-09</th>\n",
              "      <td>60.785713</td>\n",
              "      <td>61.107143</td>\n",
              "      <td>60.192856</td>\n",
              "      <td>60.247143</td>\n",
              "      <td>52.578468</td>\n",
              "      <td>98506100</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 4,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "dataset.tail()"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 5,
          "data": {
            "text/plain": [
              "                  Open        High         Low       Close   Adj Close  \\\n",
              "Date                                                                     \n",
              "2019-09-05  212.000000  213.970001  211.509995  213.279999  213.279999   \n",
              "2019-09-06  214.050003  214.419998  212.509995  213.259995  213.259995   \n",
              "2019-09-09  214.839996  216.440002  211.070007  214.169998  214.169998   \n",
              "2019-09-10  213.860001  216.779999  211.710007  216.699997  216.699997   \n",
              "2019-09-11  218.070007  223.710007  217.729996  223.589996  223.589996   \n",
              "\n",
              "              Volume  \n",
              "Date                  \n",
              "2019-09-05  23913700  \n",
              "2019-09-06  19362300  \n",
              "2019-09-09  27309400  \n",
              "2019-09-10  31777900  \n",
              "2019-09-11  44289600  "
            ],
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>Open</th>\n",
              "      <th>High</th>\n",
              "      <th>Low</th>\n",
              "      <th>Close</th>\n",
              "      <th>Adj Close</th>\n",
              "      <th>Volume</th>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>Date</th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "      <th></th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>2019-09-05</th>\n",
              "      <td>212.000000</td>\n",
              "      <td>213.970001</td>\n",
              "      <td>211.509995</td>\n",
              "      <td>213.279999</td>\n",
              "      <td>213.279999</td>\n",
              "      <td>23913700</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2019-09-06</th>\n",
              "      <td>214.050003</td>\n",
              "      <td>214.419998</td>\n",
              "      <td>212.509995</td>\n",
              "      <td>213.259995</td>\n",
              "      <td>213.259995</td>\n",
              "      <td>19362300</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2019-09-09</th>\n",
              "      <td>214.839996</td>\n",
              "      <td>216.440002</td>\n",
              "      <td>211.070007</td>\n",
              "      <td>214.169998</td>\n",
              "      <td>214.169998</td>\n",
              "      <td>27309400</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2019-09-10</th>\n",
              "      <td>213.860001</td>\n",
              "      <td>216.779999</td>\n",
              "      <td>211.710007</td>\n",
              "      <td>216.699997</td>\n",
              "      <td>216.699997</td>\n",
              "      <td>31777900</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2019-09-11</th>\n",
              "      <td>218.070007</td>\n",
              "      <td>223.710007</td>\n",
              "      <td>217.729996</td>\n",
              "      <td>223.589996</td>\n",
              "      <td>223.589996</td>\n",
              "      <td>44289600</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "</div>"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 5,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import scipy.fftpack"
      ],
      "outputs": [],
      "execution_count": 6,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "xf = scipy.fftpack.fft(dataset['Open'])\n",
        "yf = scipy.fftpack.fft(dataset['Adj Close'])"
      ],
      "outputs": [],
      "execution_count": 7,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "xf"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 8,
          "data": {
            "text/plain": [
              "array([235811.260154      +0.j        ,  13368.38247208+43970.90770083j,\n",
              "         3730.78644277+31495.26999718j, ...,\n",
              "         -915.67721325  -979.97709717j,   3730.78644277-31495.26999718j,\n",
              "        13368.38247208-43970.90770083j])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 8,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "yf"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 9,
          "data": {
            "text/plain": [
              "array([223641.5056        +0.j        ,  14133.02549618+46451.29900237j,\n",
              "         3430.01877233+32396.63588866j, ...,\n",
              "         -800.27716365 -2964.91419888j,   3430.01877233-32396.63588866j,\n",
              "        14133.02549618-46451.29900237j])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 9,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "fig, ax = plt.subplots()\n",
        "ax.plot(xf, yf)\n",
        "plt.show()"
      ],
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ],
            "image/png": [
              "iVBORw0KGgoAAAANSUhEUgAAAY0AAAD8CAYAAACLrvgBAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBodHRwOi8vbWF0c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P2C+N2ZWDZgFPOicO3SmoYXUyuLrX2wUGoVLBpoVuN0U2OVTL8XCObfL+5oKzAF6AXvMLALA+5rqDT/d/M9Ub1pIPZCUxlxPtwzfOef2OOdynXN5wCvkv/5w7vPfB9Qys7CT6j95Lu/+mkBa8c/mzMysAvmB8Y5zbrZXDunXvzgpNAq3Cmjr7SUSTv5GvXk+93TezKyqmVU/cR0YAMSTP6cTe4WMJH/9L159hLdnSR8g3Xu7vQgYYGa1vdUbA8hfn50CZJhZH29PkhEFnitQlMZcT7cM3534Y+YZRv7rD/k93+rt+dQSaEv+ht5Cfwdc/gr7pcBN3uNP/l6emP9NwOfe+FLjvSavAWudc08XuCukX/9i5fdGlUC9kL9XxQby9yB5xO9+LnAurcjf++UHIOHEfMhf37wE2Oh9rePVDXjBm3scEF3gue4CkrzLqAL1aPL/EG0C/omPG0CBd8lfBZNN/n+Gd5fGXE+3jACZ/7+8+cWS/8ctosD4R7y5rKfAXm+n+x3wfp5Wet+X/wIVvXol73aSd38rH+Z+Gfmri2KBNd5lcCi9/iV90RHhIiJSZFo9JSIiRabQEBGRIlNoiIhIkSk0RESkyBQaIiJSZAoNEREpMoWGiIgUmUJDRESK7P8B5x6E5bLRt/8AAAAASUVORK5CYII=\n"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 10,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "xf = np.fft.fft(dataset['Open'])\n",
        "yf = np.fft.fft(dataset['Adj Close'])"
      ],
      "outputs": [],
      "execution_count": 12,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "xf"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 13,
          "data": {
            "text/plain": [
              "array([235811.260154      +0.j        ,  13368.38247208+43970.90770083j,\n",
              "         3730.78644277+31495.26999718j, ...,\n",
              "         -915.67721325  -979.97709717j,   3730.78644277-31495.26999718j,\n",
              "        13368.38247208-43970.90770083j])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 13,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "yf"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 14,
          "data": {
            "text/plain": [
              "array([223641.5056        +0.j        ,  14133.02549618+46451.29900237j,\n",
              "         3430.01877233+32396.63588866j, ...,\n",
              "         -800.27716365 -2964.91419888j,   3430.01877233-32396.63588866j,\n",
              "        14133.02549618-46451.29900237j])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 14,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Discrete Fourier Transform (DFT)"
      ],
      "metadata": {}
    },
    {
      "cell_type": "code",
      "source": [
        "from scipy.linalg import dft"
      ],
      "outputs": [],
      "execution_count": 15,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    },
    {
      "cell_type": "code",
      "source": [
        "x = np.array(dataset['Open'])\n",
        "m = dft(len(dataset['Open']))\n",
        "m.dot(x)"
      ],
      "outputs": [
        {
          "output_type": "execute_result",
          "execution_count": 18,
          "data": {
            "text/plain": [
              "array([235811.260154      +0.j        ,  13368.38247208+43970.90770082j,\n",
              "         3730.78644277+31495.26999719j, ...,\n",
              "         -915.67721322  -979.97709717j,   3730.78644283-31495.26999718j,\n",
              "        13368.38247224-43970.90770077j])"
            ]
          },
          "metadata": {}
        }
      ],
      "execution_count": 18,
      "metadata": {
        "collapsed": false,
        "outputHidden": false,
        "inputHidden": false
      }
    }
  ],
  "metadata": {
    "kernel_info": {
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "pygments_lexer": "ipython3",
      "version": "3.5.5",
      "mimetype": "text/x-python",
      "file_extension": ".py",
      "name": "python",
      "nbconvert_exporter": "python"
    },
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3"
    },
    "nteract": {
      "version": "0.15.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}